/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.common.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.CrudDao;
import com.thinkgem.jeesite.common.persistence.DataEntity;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.modules.ta.entity.BResult;
import com.thinkgem.jeesite.modules.ta.entity.StDynamicResource;
import com.thinkgem.jeesite.modules.ta.entity.StUserSign;
import com.thinkgem.jeesite.modules.ta.entity.StWorktime;
import com.thinkgem.jeesite.modules.ta.entity.XtLoupan;
import com.thinkgem.jeesite.modules.ta.entity.XtSuspendApply;

/**
 * Service基类
 * 
 * @author ThinkGem
 * @version 2014-05-16
 */
@Transactional(readOnly = true)
public abstract class CrudService<D extends CrudDao<T>, T extends DataEntity<T>>
		extends BaseService {

	//生成楼盘信息
	public void insertRoom(XtLoupan xlp){
		dao.insertRoom(xlp);
	}

	public StWorktime findDate(Date sdate) {
		return dao.findDate(sdate);
	}
	public int findMax() {
		return dao.findMax();
	}

	/**
	 * 获取部门下的员工
	 * 
	 * @param id
	 * @return
	 */
	public List<StUserSign> getListByDepartId(String id) {
		return dao.getListByDepartId(id);
	}

	@Transactional(readOnly = false)
	public void updateSign(StUserSign stUserSign) {
		stUserSign.preUpdate();
		dao.updateSign(stUserSign);
	}

	/**
	 * 持久层对象
	 */
	@Autowired
	protected D dao;

	public List<T> find(String iid) {
		return dao.find(iid);
	}

	/**
	 * 获取单条数据
	 * 
	 * @param id
	 * @return
	 */
	public T get(String id) {
		return dao.get(id);
	}
	
	public T get(int fh) {
		return dao.get(fh);
	}

	//挂起
	public XtSuspendApply getXtSuspendApply(String serial) {
		return dao.getXtSuspendApply(serial);
	}

	/**
	 * 获取单条数据
	 * 
	 * @param entity
	 * @return
	 */
	public T get(T entity) {
		return dao.get(entity);
	}

	/**
	 * 查询列表数据
	 * 
	 * @param entity
	 * @return
	 */
	public List<T> findList(T entity) {
		return dao.findList(entity);
	}

	/**
	 * 查询分页数据
	 * 
	 * @param page
	 *            分页对象
	 * @param entity
	 * @return
	 */
	public Page<T> findPage(Page<T> page, T entity) {
		entity.setPage(page);
		page.setList(dao.findList(entity));
		return page;
	}

	/**
	 * 保存数据（插入或更新）
	 * 
	 * @param entity
	 */
	@Transactional(readOnly = false)
	public void save(T entity) {
		if (entity.getIsNewRecord()) {
			entity.preInsert();
			dao.insert(entity);
		} else {
			entity.preUpdate();
			dao.update(entity);
		}
	}

	@Transactional(readOnly = false)
	public void update(T entity) {
		entity.preUpdate();
		dao.update(entity);
	}
	
	// ajax更新
	@Transactional(readOnly = false)
	public void upd(T entity) {
		entity.preUpdate();
		dao.update(entity);
	}

	@Transactional(readOnly = false)
	public void insertWorkTime(StWorktime stWorktime) {
		dao.insertWorkTime(stWorktime);
	}

	@Transactional(readOnly = false)
	public void updateWorkTime(StWorktime stWorktime) {
		dao.updateWorkTime(stWorktime);
	}

	public StWorktime getWorkTime(Date sdate) {
		return dao.getWorkTime(sdate);
	}

	@Transactional(readOnly = false)
	public void updateTime(Map<String, Object> map) {
		dao.updateTime(map);
	}

	@Transactional(readOnly = false)
	public void updateTimes(Map<String, Object> map) {
		dao.updateTimes(map);
	}

	/**
	 * 删除数据
	 * 
	 * @param entity
	 */
	@Transactional(readOnly = false)
	public void delete(T entity) {
		dao.delete(entity);
	}
	/**
	 * 删除所有楼盘信息
	 * 
	 * @param entity
	 */
	@Transactional(readOnly = false)
	public void deleteAll() {
		dao.deleteAll();
	}

	public List<String> findName() {
		// TODO 自动生成的方法存根
		return dao.findName();
	}

	public List<BResult> find(Map<String, Object> map) {
		// TODO 自动生成的方法存根
		return dao.find(map);
	}

	public List<String> findQName(String userid) {
		// TODO 自动生成的方法存根
		return dao.findQName(userid);
	}

	public List<StDynamicResource> findListById(Long id) {
		return dao.findListById(id);
	}

	// 修改附件名
	@Transactional(readOnly = false)
	public void StDynamicResourceUpdateName(Map<String, Object> map) {
		dao.StDynamicResourceUpdateName(map);
	}

	// 附件删除
	public void StDynamicResourceDelAll(Long iid) {
		dao.StDynamicResourceDelAll(iid);
	}

	public void StDynamicResourceDelOne(String resValue) {
		dao.StDynamicResourceDelOne(resValue);
	}

	public void StAttachmentDelOne(String aid) {
		dao.StAttachmentDelOne(aid);
	}

	public void StAttachmentDelAll(Long iid) {
		dao.StAttachmentDelAll(iid);
	}

	public List<StWorktime> findAllListWorkTime() {
		return dao.findAllListWorkTime();
	}

}
